package com.example.dangerouscargodriver.ui.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;

import com.example.dangerouscargodriver.MainActivity;
import com.example.dangerouscargodriver.R;
import com.example.dangerouscargodriver.controller.AreaInfoController;
import com.example.dangerouscargodriver.controller.AttrInfoController;

import java.lang.ref.WeakReference;

public class LaunchActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        hideNavigationBar();
        setContentView(R.layout.activity_launch);

        new CheckMethod(this).execute();
    }

    private void gotoMain() {

        new Handler().postDelayed(()->{
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            finish();
        }, 3000);
    }

    private void gotoLogin() {

        new Handler().postDelayed(()->{
            Intent intent=new Intent();
            intent.setAction("intent.action.baiju.http.LOGIN");
            startActivity(intent);
            finish();
        }, 5000);
    }

    private static class CheckMethod extends AsyncTask<Void, Void, Boolean> {

        private WeakReference<LaunchActivity> wr;

        public CheckMethod(LaunchActivity activity) {

            wr = new WeakReference<>(activity);
        }

        @Override
        protected Boolean doInBackground(Void... voids) {

            boolean result = false;

            return result;
        }

        @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            LaunchActivity activity = wr.get();
            if (activity != null) {
                activity.gotoMain();
            }
        }
    }

    private void hideNavigationBar() {
        if(getWindow()!=null){
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE);
        }
    }
}